﻿
$(document).ready(function() {
    JSUtility.url = '../Handler/AjaxHandle.ashx';
    JSUtility.param = { AssemblyName: "OA.Bll.Personnel", ClassName: "OA.Bll.Personnel.PerformancePresenter", Method: "Paged", Options: {} };
    top.autoResize({ dataGrid: '#Grid', callback: InitPerformancelist, par: {}, method: 'Paged' });
    JSUtility.window_edit_form = $("#PerformanceWin").find("form");
    JSUtility.window_edit = $("#PerformanceWin");
    JSUtility.window_edit_title = "职级信息维护";
    $("#btnAdd").click(function() {
        JSUtility.add();
    });
    $("#btnDel").click(JSUtility.del);
    $("#btnEdit").click(function() {
        var rows = $("#Grid").datagrid('getSelections');
        var num = rows.length;
        if (num == 0) {
            $.messager.alert('提示', '请选择一条记录进行操作!', 'info');
            return;
        }
        else {
            $("#IsExceptional").prop("checked", rows[0].IsExceptional);
        }
        JSUtility.update();
    });
    $("#btnSubmit").click(function() {
        JSUtility.param.Options["EmployeeID"] = $("#EmployeeId").combotree('getValue');
        JSUtility.param.Options["IsExceptional"] = $("#IsExceptional").prop("checked");
        JSUtility.param.Options["JobLevel"] = $("#JobLevel").combotree('getText');
        JSUtility.param.Options["JobRank"] = $("#JobRank").combotree('getText');
        JSUtility.param.Options["SuitableSalary"] = $("#SuitableSalary").combotree('getText');
        JSUtility.param.Options["JobType"] = $("#JobType").combotree('getText');
        JSUtility.param.Options["Series"] = $("#Series").combotree('getText');
        JSUtility.param.Options["AssessmentLevelId"] = $("#AssessmentLevelId").combotree('getText');
        JSUtility.save();
    });
    $('#btnCancel').click(JSUtility.close);
    $("#JobType").combobox({
        url: '../Handler/AjaxComboboxData.ashx?typeId=27',
        valueField: 'id',
        textField: 'text',
        panelHeight: 'auto',
        onChange: function(newValue, oldValue) {
            alert(newValue);
            $.ajax({
                type: "post",
                url: '../Handler/AjaxComboboxData.ashx?id=' + newValue,
                dataType: "json",
                success: function(data) {
                    $('#Series').combotree('loadData', data
                    );
                }
            });
        }
    });
    //    $('#Year').datebox({
    //        onSelect: function(date) {
    //            $('#Year').datebox('setValue', date.getFullYear()); // set datebox value
    //        }
    //    });
    //    $('#Month').datebox({
    //        onSelect: function(date) {
    //            $('#Month').datebox('setValue', date.getMonth() + 1); // set datebox value
    //        }
    //    });
});

function InitPerformancelist(op, method, size) {
    var p = JSUtility.param;
    p.Method = "Paged";
    JSUtility.grid = $('#Grid').datagrid({
        fitColumns: true,
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        striped: true,
        queryParams: { "json": $.toJSON(p) },
        url: JSUtility.url,
        singleselect: true,
        view: detailview,
        detailFormatter: function(rowIndex, data) {
            var result = '<table style="width:800px;" cellpadding="1" cellspacing="1">';
            result += '<tr>';
            result += '<td style ="vertical-align: top;" class="td2">年度：</td>';
            result += '<td id="tdYear"  style ="vertical-align: top;width:200px" >' + data.Year + '</td>';
            result += '<td style ="vertical-align: top" class="td2">月份：</td>';
            result += '<td id="tdMonth" width="200px">' + data.Month + '</td>';
            result += '</tr>';
            result += '<tr>';
            result += '<td style ="vertical-align: top;" class="td2">职级：</td>';
            result += '<td id="tdYear"  style ="vertical-align: top;width:200px" >' + data.TitleImage + '</td>';
            result += '<td style ="vertical-align: top" class="td2">职级年限：</td>';
            result += '<td id="tdMonth" width="200px">' + data.JobLevelYears + '</td>';
            result += '</tr>';
            result += '<tr>';
            result += '<td style ="vertical-align: top;" class="td2">职等：</td>';
            result += '<td id="tdYear"  style ="vertical-align: top;width:200px" >' + data.JobRank + '</td>';
            result += '<td style ="vertical-align: top" class="td2">适用薪酬表：</td>';
            result += '<td id="tdMonth" width="200px">' + data.SuitableSalary + '</td>';
            result += '</tr>';
            result += '<tr>';
            result += '<td style ="vertical-align: top;" class="td2">职位类：</td>';
            result += '<td id="tdYear"  style ="vertical-align: top;width:200px" >' + data.JobType + '</td>';
            result += '<td style ="vertical-align: top" class="td2">职位序列/子序列：</td>';
            result += '<td id="tdMonth" width="200px">' + data.Series + '</td>';
            result += '</tr>';
            result += '<tr>';
            result += '<td style ="vertical-align: top;" class="td2">总匹配度：</td>';
            result += '<td id="tdYear"  style ="vertical-align: top;width:200px" >' + data.MatchDegree + '</td>';
            var exceptional="不破格提拔";
            if (data.IsExceptional == "True") {
                exceptional = "破格提拔";
            }

            result += '<td style ="vertical-align: top" class="td2">是否破格：</td>';
            result += '<td id="tdMonth" width="200px">' + exceptional + '</td>';
            result += '</tr>';
            result += '<tr>';
            result += '<td style ="vertical-align: top;" class="td2">考核结果：</td>';
            result += '<td id="tdYear"  style ="vertical-align: top;width:200px" colspan="3">' + data.AssessmentTime + '</td>';
            result += '</tr>';

            result += '</table>';
            return result;
        }
    });
}